﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SOWY.common;

namespace SOWY
{
    class TaskFormatter
    {
        public string task;
        public string dateKey;
        public string[] parameter { get; set; }
        public string[] newValue { get; set; }
        public string[] oldtokens { get; set; }
        public string[] newtokens { get; set; }
        private int taskNum { get; set; }

        public TaskFormatter()
        {
            task = "";
        }
        public TaskFormatter(string input, string dateKey, int taskN)
        {
            this.task = input;
            this.dateKey = dateKey;
            this.taskNum = taskN;
            parameter = new string[1];
            newValue = new string[1];
            oldtokens = new string[1];
            newtokens = new string[1];
        }

        public void formatTaskforUpdate()
        {
            task = task.Replace(" to ", "~");
            string[] temp = task.Split('~');
            oldtokens = temp[0].Split('|');
            newtokens = temp[1].Split('|');

            if (dateKey.CompareTo(GeneralConstant.KEY_FOR) == 0)
            {
                parameter[0] = GeneralConstant.KEY_ENDDATE;
            }
            else
            {
                parameter[0] = GeneralConstant.KEY_TASK;
            }

            if (newtokens.Length == 1)
                newValue[0] = newtokens[0];
            else if (newtokens.Length == oldtokens.Length)
                newValue[0] = newtokens[taskNum];
            else
                newValue = null;

        }
    }
}
